'use strict';

var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var ejs = require('ejs');

var commodity = require('./modules/commodity.js');

var app = express();

app.engine('html', ejs.renderFile);
app.set('view engine', 'ejs');
app.set('views', 'app/views');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: true
}));
app.use('/assets', express.static('app'));
app.use('/assets', express.static('node_modules'));

// Routes
app.get('/', function (req, res, next) {
  res.render('index.html', {title: 'E-Bussiness'});
});

app.get('/commodity', function (req, res, next) {
  res.render('commodityList.html', {title: 'E-Bussiness'});
});

// Apis
app.get('/api/commodity', commodity.list);
app.post('/api/commodity/add', commodity.add);
app.post('/api/commodity/del', commodity.del);

app.listen(3000);
